package com.yh.supergo.manager.controller;

import com.yh.supergo.http.HttpResult;
import com.yh.supergo.manager.feign.BrandFeignClient;
import com.yh.supergo.pojo.Brand;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 0715-YuHao
 * @version 1.0
 * @className BrandController
 * @description 控制器
 * @date 2020/11/16 17:49
 */
@RestController
@RequestMapping("/brand")
@Api(value = "品牌控制器")
public class BrandController {

    @Autowired
    private BrandFeignClient brandFeignClient;

    @ApiOperation(value = "根据ID查询品牌", notes = "根据ID查询品牌")
    @ApiImplicitParam(paramType = "path", name = "brandId", value = "商品ID")
    @GetMapping("/{brandId}")
    public HttpResult getBrandById(@PathVariable long brandId) {
        Brand brand = brandFeignClient.findOne(brandId);
        return HttpResult.ok(brand);
    }

    @ApiOperation(value = "品牌分页查询", notes = "接受分页参数page, rows")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page",
                    value = "第几页", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "path", name = "size",
                    value = "一页显示多少数据", required = true, dataType = "int")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "条件分页查询品牌成功"),
            @ApiResponse(code = 500, message = "条件分页查询品牌失败，后台服务出现异常"),
            @ApiResponse(code = 401, message = "此操作无权限访问"),
            @ApiResponse(code = 400, message = "请求参数错误"),
    })
    @PostMapping("/query/{page}/{size}")
    public HttpResult getBrandPage(@RequestBody(required = false)Brand brand,
                                   @PathVariable int page,
                                   @PathVariable int size) {
        return brandFeignClient.findPage(brand, page, size);
    }
}
